package com.cictec.cloud.netbus.order.rest;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * @author :zoboy
 * @Description:
 * @ Date: Created in 2020-05-09 14:08
 */
@RestController
public class UploadController {

    @PostMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String handleFileUpload(HttpServletRequest request,  @RequestPart(value = "file") MultipartFile file) {
//        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
        File dest = new File("E:\\uploadFiles\\"+file.getOriginalFilename());
        try {
            file.transferTo(dest);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return file.getName();
    }
}
